﻿/**
 * FFXIIRCGateway
 *
 * @package ffxiircgateway
 * @version $Id: SettingForm.cs 22 2009-05-10 02:17:33Z ayunyan $
 * @author ayunyan <ayu@commun.jp>
 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @link http://code.google.com/p/ffxiircgateway
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FFXIIRCGateway
{
    public partial class SettingForm : Form
    {
        private int[] encodings = new int[] {
            50220, // ISO-2022-JP
            65001  // UTF-8
        };
        private string[] defaultChat = { "Linkshell", "Party", "Say" };

        public SettingForm()
        {
            InitializeComponent();
            for (int i = 0; i < this.encodings.Length; i++) {
                this.comboEncoding.Items.Add(Encoding.GetEncoding(this.encodings[i]).WebName);
                if (this.encodings[i] == Properties.Settings.Default.Encoding)
                {
                    this.comboEncoding.SelectedIndex = i;
                }
            }
            this.textHost.Text = Properties.Settings.Default.Host;
            this.updownPort.Value = Properties.Settings.Default.Port;
            this.textServerPassword.Text = Properties.Settings.Default.ServerPassword;
            this.textNickName.Text = Properties.Settings.Default.NickName;
            this.textUserName.Text = Properties.Settings.Default.UserName;
            this.textRealName.Text = Properties.Settings.Default.RealName;
            this.textNickServPassword.Text = Properties.Settings.Default.NickServPassword;
            this.textChannel.Text = Properties.Settings.Default.Channel; 
            this.checkAutoConnect.Checked = Properties.Settings.Default.AutoConnect;

            this.textIRCBotNick.Text = Properties.Settings.Default.IRCBotNick;

            this.checkRecvLinkshell.Checked = Properties.Settings.Default.RecvChatLS;
            this.checkRecvParty.Checked = Properties.Settings.Default.RecvChatParty;
            this.checkRecvSay.Checked = Properties.Settings.Default.RecvChatSay;
            this.checkRecvTell.Checked = Properties.Settings.Default.RecvChatTell;
            this.checkSendLinkshell.Checked = Properties.Settings.Default.SendChatLS;
            this.checkSendParty.Checked = Properties.Settings.Default.SendChatParty;
            this.checkSendSay.Checked = Properties.Settings.Default.SendChatSay;
            this.checkSendTell.Checked = Properties.Settings.Default.SendChatTell;
            for (int i = 0; i < this.defaultChat.Length; i++)
            {
                this.comboDefaultChat.Items.Add(this.defaultChat[i]);
            }
            this.comboDefaultChat.SelectedIndex = Properties.Settings.Default.DefaultChat;
            this.textCommandPrefix.Text = Properties.Settings.Default.CommandPrefix;
        }

        private void SettingForm_Load(object sender, EventArgs e)
        {

        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.Encoding = this.encodings[this.comboEncoding.SelectedIndex];
            Properties.Settings.Default.Host = this.textHost.Text;
            Properties.Settings.Default.Port = (int)this.updownPort.Value;
            Properties.Settings.Default.ServerPassword = this.textServerPassword.Text;
            Properties.Settings.Default.NickName = this.textNickName.Text;
            Properties.Settings.Default.UserName = this.textUserName.Text;
            Properties.Settings.Default.RealName = this.textRealName.Text;
            Properties.Settings.Default.NickServPassword = this.textNickServPassword.Text;
            Properties.Settings.Default.Channel = this.textChannel.Text;
            Properties.Settings.Default.AutoConnect = this.checkAutoConnect.Checked;

            Properties.Settings.Default.IRCBotNick = this.textIRCBotNick.Text;

            Properties.Settings.Default.RecvChatLS = this.checkRecvLinkshell.Checked;
            Properties.Settings.Default.RecvChatParty = this.checkRecvParty.Checked;
            Properties.Settings.Default.RecvChatSay = this.checkRecvSay.Checked;
            Properties.Settings.Default.RecvChatTell = this.checkRecvTell.Checked;
            Properties.Settings.Default.SendChatLS = this.checkSendLinkshell.Checked;
            Properties.Settings.Default.SendChatParty = this.checkSendParty.Checked;
            Properties.Settings.Default.SendChatSay = this.checkSendSay.Checked;
            Properties.Settings.Default.SendChatTell = this.checkSendTell.Checked;
            Properties.Settings.Default.DefaultChat = this.comboDefaultChat.SelectedIndex;
            Properties.Settings.Default.CommandPrefix = this.textCommandPrefix.Text;

            Properties.Settings.Default.Save();
            this.Close();
        }
    }
}
